﻿<%@ Page Title="Content Explorer" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<asp:Content ContentPlaceHolderID="MainContent" runat="server">

<div class="toolbar">
   <button class="button rebuild-similarity-cache">Rebuild Similarity Cache</button>
   <button class="button rebuild-search-index">Rebuild Search Index</button>
</div>

<div id="content-explorer">
<%: Html.Action("ContentExplorerDirectory", "ContentManagement") %>
</div>
</asp:Content>

<asp:Content ContentPlaceHolderID="ScriptContent" runat="server">
<script>
    $('.rebuild-similarity-cache').click(function () {
        $.get('/ContentManagement/SimilarityCacheRebuild', function () {
            alert('Rebuild complete.');
        });
        alert('Rebuild started...');
    });

    $('.rebuild-search-index').click(function () {
        $.get('/ContentManagement/RebuildSearchIndex', function () {
            alert('Rebuild complete.');
        });
        alert('Rebuild started...');
    });

    $('#content-explorer .content-explorer-directory').live('click', function () {
        var anchor = $(this)
            , path = '';

        if (anchor.data('tree-loaded')) return;

        anchor.data('tree-loaded', true);
        anchor.parentsUntil('#content-explorer').children('a').each(function () { path += $(this).html(); });

        $.post('/ContentManagement/ContentExplorerDirectory', { path: path }, function (data, status, xhr) {
            anchor.parent().append(data);
        });
    });
</script>
</asp:Content>